package org.altervista.cp.thinbcgen.proxy.test;

import java.io.PrintStream;

import org.altervista.cp.thinbcgen.proxy.ExceptionHandler;
import org.altervista.cp.thinbcgen.proxy.UpdatableProxy;

public abstract class TargetProxy implements Source, UpdatableProxy {

	public int unimplementedReader() {
		throw new UnsupportedOperationException(
				"The unimplementedReader() method is not implemented by the org.altervista.cp.proxygen.test.Source interface");
	}

	public void unimplementedWriter() {
		throw new UnsupportedOperationException(
				"The unimplementedWriter() method is not implemented by the org.altervista.cp.proxygen.test.Source interface");
	}

	public String getName(int value) {
		try {
			return ((Source) _source).getName(value);
		} catch (Throwable t) {
			return (String) _eh.handle(this, t, "getName",
					new Object[] { value });
		}
	}

	public int setName(int value) {
		try {
			return value;
		} catch (Throwable t) {
			return ((Integer) _eh.handle(this, t, "setName",
					new Object[] { value })).intValue();
		}
	}

	public TargetProxy() {
	}

	public TargetProxy(Object source) {
		_source = source;
	}

	public int getNumber() {
		return _number;
	}

	public void printName(PrintStream out) throws Exception {
		out.println("My name is: " + getName(_number).toUpperCase());
	}

	private int _number;
	private ExceptionHandler _eh;
	private Object _source;

}
